#include "mainwindow.h"
#include "MyQTextEdit.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    connect(ui->pushButton_display,
            SIGNAL(clicked()),SLOT(OnPushPlaySlot()));
    connect(ui->pushButton_clean,
            SIGNAL(clicked()),SLOT(OnPushCleanSlot()));
    connect(ui->horizontalSlider,
            SIGNAL(valueChanged(int)),SLOT(OnSliderChanged(int)));
    connect(ui->lcdNumber,
            SIGNAL(valueChanged(int)),SLOT(OnLcdChanged(int)));
    connect(ui->pushButton_pause,
            SIGNAL(clicked()),SLOT(OnPushPauseSlot()));
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::OnPushPlaySlot()
{
    QString displayString = ui->textEdit_input->toPlainText();
    ui->textEdit_display->SetText(displayString);
    ui->textEdit_input->clear();

    ui->textEdit_display->CreateTimer(1000);
    ui->textEdit_display->SetPlaySpeed(ui->lcdNumber->value());
}

void MainWindow::OnPushCleanSlot()
{
    ui->textEdit_display->CancleTimer();
    ui->textEdit_display->CleanEdit();
}

void MainWindow::OnPushPauseSlot()
{
    ui->textEdit_display->SetPause(false);
    //ui->pushButton_pause->
}

void MainWindow::OnSliderChanged(int value)
{
    ui->lcdNumber->display(value);
    ui->textEdit_display->SetPlaySpeed(value);
}

void MainWindow::OnLcdChanged(int value)
{
    ui->textEdit_display->SetPlaySpeed(value);
}

